// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

document.observe('dom:loaded', function() {
	$('darken').observe('click', hidePopup);
	if($('member_name') != null)
	{
		$('member_name').observe('blur', function(event) {
			var e = event.element();
			if(e.value == '') {
				e.value = 'find member';
			}
		});
		$('member_name').observe('focus', function(event) {
			var e = event.element();
			if (e.value == 'find member') {
				e.clear();
			}
		});
	}
});

function showPopup()
{
	Element.Center($("popupBox"));
	$("popupBox").style.display = "block";
	$("darken").style.display = "block";
}

function hidePopup()
{
	$("popupBox").style.display = "none";
	$("darken").style.display = "none";
}

function showTooltip(position)
{
	$("tooltip").style.left = position.left + 'px';
  $("tooltip").style.top = position.top + 'px';
	$("tooltip").style.display = "block";
}

function hideTooltip()
{
	$("tooltip").style.display = "none";
}

//-------------------- Prototype extensions ------------------------

Position.GetWindowSize = function() {
	var width;
	var height;

	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	if (typeof window.innerWidth != 'undefined')
	{
		width = window.innerWidth,
		height = window.innerHeight
	}
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	else if (typeof document.documentElement != 'undefined'
	&& typeof document.documentElement.clientWidth !=
	'undefined' && document.documentElement.clientWidth != 0)
	{
		width = document.documentElement.clientWidth,
		height = document.documentElement.clientHeight
	}
	// older versions of IE
	else
	{
		width = document.getElementsByTagName('body')[0].clientWidth,
		height = document.getElementsByTagName('body')[0].clientHeight
	}
	return [width, height]
}

Element.Center = function(element) {
  var w, h, pw, ph;
  var d = Element.getDimensions(element);
  w = d.width;
  h = d.height;
  var ws = Position.GetWindowSize();
  pw = ws[0];
  ph = ws[1];
  element.style.top = (ph/2) - (h/2) + "px";
  element.style.left = (pw/2) - (w/2) + "px";
}
